//
//  CalcuBusDriection.m
//  DriverBus
//
//  Created by MacMini20170218 on 2017/3/31.
//  Copyright © 2017年 JiYang. All rights reserved.
//

#import "CalcuBusDriection.h"
#import <math.h>

static double oldlatitude = 0;
static double oldlongitude = 0;
static float directionRotate =0;

@implementation CalcuBusDriection

+ (float)directionRotate:(double)lat longitude:(double)log{
    double offLat = lat - oldlatitude;
    double offLog = log - oldlongitude;
    if(offLat !=0 || offLog !=0){
        //获取斜边
        double xiebian = sqrt(offLog*offLog + offLat*offLat);
        //比较差值
        if(fabs(offLat) > fabs(offLog)){
            directionRotate = (float)(asin(offLat/xiebian)*(180 / M_PI));
            if(offLat < 0){
                directionRotate = 180 - directionRotate;
            }
        }else{
            directionRotate = (float)(acos(offLog / xiebian)*(180 / M_PI));
            if(offLat<0){
                directionRotate = directionRotate * (-1);
            }
        }
        //更新经纬
        oldlatitude = lat;
        oldlongitude = log;
    }
    return directionRotate;
}

@end
